import java.util.LinkedList;
import java.util.ListIterator;


public class Test {
    public static void main(String[] args) {
        LinkedList<Integer> linkedList=new LinkedList<>();
        linkedList.add(1);
        linkedList.add(2);
        linkedList.add(3);
        //直接遍历
        System.out.println(linkedList);
        //for循环遍历
        for (int i = 0; i <linkedList.size() ; i++) {
            System.out.print(linkedList.get(i)+" ");
        }
        System.out.println();
        //foreach遍历
        for (int i:linkedList) {
            System.out.print(i+" ");
        }
        System.out.println();
        //迭代器遍历
        ListIterator<Integer> iterator=linkedList.listIterator();
        while (iterator.hasNext()){
            System.out.print(iterator.next()+" ");
        }
        System.out.println();
        ListIterator<Integer> iterator1=linkedList.listIterator(linkedList.size());
        while (iterator1.hasPrevious()){
            System.out.print(iterator1.previous()+" ");
        }
        System.out.println();

    }
    public static void main6(String[] args) {
        LinkedList<Integer> linkedList=new LinkedList<>();
        LinkedList<Integer> linkedList1=new LinkedList<>();
        linkedList1.add(55);
        linkedList1.add(66);
        //尾插
        linkedList.add(11);
        linkedList.add(22);
        linkedList.add(33);
        System.out.println(linkedList);
        //元素插入index位置
        linkedList.add(0,0);
        linkedList.add(4,44);
        System.out.println(linkedList);
        //插入其他链表的元素
        linkedList.addAll(linkedList1);
        System.out.println(linkedList);
        //删除元素
        linkedList.remove(0);
        linkedList.remove(4);
        System.out.println(linkedList);
        //获取下标元素
        System.out.println(linkedList.get(3));
        //设置index元素
        linkedList.set(1,111);
        System.out.println(linkedList);
        //判断元素是否存在
        System.out.println(linkedList.contains(44));
        System.out.println(linkedList.contains(22));
        //返回下标
        System.out.println(linkedList.indexOf(55));
        System.out.println(linkedList.lastIndexOf(111));
        //截取
        System.out.println(linkedList.subList(0, 4));
        //清空
        System.out.println(linkedList);
        linkedList.clear();
        System.out.println(linkedList);


    }
    public static void main5(String[] args) {
        DoubleLinkedList doubleLinkedList=new DoubleLinkedList();
        doubleLinkedList.addLast(1);
        doubleLinkedList.addLast(3);
        doubleLinkedList.addLast(2);
        doubleLinkedList.addLast(3);
        doubleLinkedList.addLast(4);
        doubleLinkedList.display();
        doubleLinkedList.clear();
    }
    public static void main4(String[] args) {
        DoubleLinkedList doubleLinkedList=new DoubleLinkedList();
        doubleLinkedList.addLast(1);
        doubleLinkedList.addLast(3);
        doubleLinkedList.addLast(2);
        doubleLinkedList.addLast(3);
        doubleLinkedList.addLast(4);
        doubleLinkedList.display();
        doubleLinkedList.remove(3);
        doubleLinkedList.display();
        doubleLinkedList.removeAllKey(3);
        doubleLinkedList.display();

    }
    public static void main3(String[] args) {
        DoubleLinkedList doubleLinkedList=new DoubleLinkedList();
        doubleLinkedList.addLast(1);
        doubleLinkedList.addLast(2);
        doubleLinkedList.addLast(3);
        doubleLinkedList.display();
        doubleLinkedList.addIndex(0,0);
        doubleLinkedList.addIndex(4,4);
        doubleLinkedList.display();
    }
    public static void main2(String[] args) {
        DoubleLinkedList doubleLinkedList=new DoubleLinkedList();
        doubleLinkedList.addLast(1);
        doubleLinkedList.addLast(2);
        doubleLinkedList.addLast(3);
        doubleLinkedList.display();
    }
    public static void main1(String[] args) {
        DoubleLinkedList doubleLinkedList=new DoubleLinkedList();
        doubleLinkedList.addFirst(11);
        doubleLinkedList.addFirst(22);
        doubleLinkedList.addFirst(33);
        doubleLinkedList.addFirst(44);
        doubleLinkedList.addFirst(55);
        doubleLinkedList.display();
        System.out.println(doubleLinkedList.size());
        System.out.println(doubleLinkedList.contains(33));
        System.out.println(doubleLinkedList.contains(66));


    }
}
